import { defineStore, storeToRefs } from 'pinia'
export const useUserStore = defineStore('user', {
	state: () => (<{
		userInfo : any,
		access_token : string,
		refresh_token : string,
		shareRefereeId : string,
		userfromInfo ?: any
		shareStudioId ?: string | number,
		isCheck ?: string | number,
	}>{
			userInfo: "",
			access_token: "",
			refresh_token: "",
			shareRefereeId: "",//分享链接携带的推荐人id
			shareStudioId: "",//分享工作室携带id
			userfromInfo: {},//聊天对象的用户信息id 名字  头像
			isCheck: "",
		}),
	persist: {
		storage: {
			getItem: (key : string) => uni.getStorageSync(key),
			setItem: (key : string, value : string) => uni.setStorageSync(key, value)
		}
	}

})

export const useUserStoreToRefs = () => {
	return storeToRefs(useUserStore())
}

export const reset = () => {
	let storeObj = useUserStore()
	storeObj.userInfo = ""
	storeObj.access_token = ""
	storeObj.refresh_token = ""
	storeObj.userfromInfo = {}
	// useUserStore().$reset()   
}
// 使用
// import { useImStoreToRefs } from '@/store/useImStore'
// const { imServer } = useImStoreToRefs()